package yxy.game.pm2.active.command.sdk.weixin.heroshare;

import yxy.apple.logger.Logger;
import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.active.module.sdk.weixin.ActiveModule_武将分享;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.SdkActiveMessage;
import yxy.game.pm2.message.SdkActiveMessage.WeiXinHeroCanShareRequest;

/**
 * 在线礼包
 * @author Dell
 *
 */
@MessageType(proto = Command.WeiXinHeroCanShare, classtype = SdkActiveMessage.WeiXinHeroCanShareRequest.class)
public class CMD_Active_武将分享_CanShare extends Command<WeiXinHeroCanShareRequest> {
	
	private static final Logger logger = Logger.create(CMD_Active_武将分享_CanShare.class);
	
	@Override
	public void execute(MessageSource messageSource, WeiXinHeroCanShareRequest request) throws Exception {
		String pcode = messageSource.getTag();
		int heroid = request.getHeroid();
		SdkActiveMessage.WeiXinHeroCanShareResponse.Builder response = SdkActiveMessage.WeiXinHeroCanShareResponse.newBuilder();
		
		ActiveModule_武将分享 am = ActiveModule_武将分享.get(pcode);
		if(am == null) {
			send(messageSource, response, Result.ActNoOpen);
			return;
		}
				
		response.setCanshare(!am.getShareheroids().contains(heroid));
		send(messageSource, response, Result.Success);
	}

	private void send(MessageSource messageSource, SdkActiveMessage.WeiXinHeroCanShareResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
	
}
